package so.sao.code.service.infrastructure;

import so.sao.code.service.domain.entity.TagTask;
import so.sao.code.service.repository.TagTaskDao;
import so.sao.top.core.util.mapper.JsonMapper;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by Administrator on 2017/10/26.
 */
public class InternalEventStore {
    static BlockingQueue events = new LinkedBlockingQueue();


    /**
     * 事件持久化
     */
    public static void save(Object event) {
        TagTaskDao tagTaskDao = WebContext.context.getBean(TagTaskDao.class);
        JsonMapper jsonMapper = WebContext.context.getBean(JsonMapper.class);
        TagTask tagTask = new TagTask(event.getClass().toString(), jsonMapper.toJson(event));
        tagTaskDao.save(tagTask);
    }


    public static void put(Object event) {
        events.add(event);
    }

    public static BlockingQueue getEvents() {
        return events;
    }

    public static void clear() {
        events.clear();
    }
}
